var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    buyId:0,
    lingqu:0,
    bigMask: false,
    receiveid:0,
  },
  zengli:function(){
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/vippay/vippay?type=2',
    })
  },

  islingqu:function(){
    var that = this;
    console.log(wx.getStorageSync('openid'),that.data.receiveid)
    app.util.request({
      'url': 'entry/wxapp/huiyuan.zengsong_lingqu',
      data: {
        openid: wx.getStorageSync('openid'),
        receiveid:that.data.receiveid,
      },
      success: function (res) {
        if(res.data=='领取成功'){
          wx.showToast({
            title: '领取成功',
          }) 
          setTimeout(function () {
            wx.reLaunch({
              url: '/hyb_yl/tabBar/index/index',
            })
          }, 1000)
        }else{
          wx.showToast({
            title: "领取失败",
            icon:"none"
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var openid = wx.getStorageSync('openid')
    if (openid) {
      that.setData({
        bigMask: true
      })
    } else {
      that.setData({
        bigMask: false
      })
    }
    app.util.request({
      'url': 'entry/wxapp/huiyuan.setting',
      data: {
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        that.setData({
          setting_zengsong_thumb: res.data.setting_zengsong_thumb,
          setting_title:res.data.setting_title,
          setting_content:res.data.setting_zengsong_content,
        })
      }
    })

    if(options.receiveid!=undefined){
      app.util.request({
        'url': 'entry/wxapp/huiyuan.zengsong_lingquinfo',
        data: {
          receiveid:options.receiveid,
        },
        success: function (res) {

          that.setData({
            lingqu:1,
            receiveid:options.receiveid,
            zhufu: res.data.s_content,
          })
        }
      })
      
    }
  },
  zhufuyu:function(e){
    var that = this;
    that.setData({
      zhufu:e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;

    app.util.request({
      'url': 'entry/wxapp/huiyuan.zengsong_give',
      data: {
        openid: wx.getStorageSync('openid'),
        buyId:that.data.buyId,
        zhufu:that.data.zhufu,
      }
    })
    return {
      title: "会员赠送",
      path: '/hyb_yl/backstageServices/pages/givevip/givevip?receiveid=' + that.data.buyId,
      success: function(res) {
        console.log(res, "转发成功")
      },
      fail: function(res) {
        console.log(res, "转发失败")
      }
    }
  }
})